package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.HomeBannerAddDTO;
import org.jsola.hr.dto.HomeBannerUpdateDTO;
import org.jsola.hr.entity.HomeBannerDO;
import org.jsola.hr.query.HomeBannerQuery;
import org.jsola.hr.service.IHomeBannerService;
import org.jsola.hr.vo.HomeBannerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 卫人云-首页Banner管理
 *
 * @author zhr
 */
@Component
public class HomeBannerTestHelper extends BaseTestHelper {
    
    @Autowired
    private IHomeBannerService homeBannerService;

    /**
     * 生成add测试数据
     * @return HomeBannerAddDTO
     */
    public HomeBannerAddDTO getHomeBannerAddDTO(){
        HomeBannerAddDTO homeBannerAddDTO = new HomeBannerAddDTO();
        homeBannerAddDTO.setUrl(getRandomValue("varchar",500));
        homeBannerAddDTO.setJumpLink(getRandomValue("varchar",500));
        homeBannerAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        return homeBannerAddDTO;
    }


    /**
     * 生成update测试数据
     * @return HomeBannerUpdateDTO
     */
    public HomeBannerUpdateDTO getHomeBannerUpdateDTO(HomeBannerVO homeBannerVO){
        return homeBannerService.selectDOById(homeBannerVO.getId(), SITE_ID).to(HomeBannerUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return HomeBannerQuery
     */
    public HomeBannerQuery getHomeBannerQuery() {
        HomeBannerQuery homeBannerQuery = new HomeBannerQuery();
        List<HomeBannerDO> homeBannerDOList = homeBannerService.list(new HomeBannerDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(homeBannerDOList)) {
            HomeBannerDO homeBannerDO = homeBannerDOList.get(0);
            homeBannerQuery = homeBannerDO.to(HomeBannerQuery.class);
        }
        return homeBannerQuery;
    }

    /**
     * 保存示例
     * @return HomeBannerVO
     */
    public HomeBannerVO saveHomeBannerExample(){
        HomeBannerAddDTO addDTO = this.getHomeBannerAddDTO();
        HomeBannerVO homeBannerVO = homeBannerService.save(addDTO,buildTokenUser());
        return homeBannerVO;
    }


}

